package org.bf.sms.persistent.sqlmapdao.login;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.bf.sms.domain.user.Account;
import org.bf.sms.persistent.iface.login.DaoAccount;
import org.springframework.beans.factory.annotation.Autowired;

import com.ibatis.sqlmap.client.SqlMapClient;

/**
 * DAO--account
 * 
 * @author LiuChang 2010-12-15
 * @version 1.0
 * @since 1.0
 */
public class DaoAccountImpl implements DaoAccount
{

	/** DB session */
	@Autowired
	private SqlMapClient sqlMapClient;

	/**
	 * constructor
	 */
	public DaoAccountImpl()
	{
		super();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see com.DaoAccount.sms.persistence.iface.AccountDao#query(String)
	 *      (com.jinye.sms.domain.Account)
	 */
	public Account getAccount(String username) throws SQLException
	{

		return (Account) this.sqlMapClient.queryForObject(
				"queryAccountByUsername", username);
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see com.DaoAccount.sms.persistence.iface.AccountDao#insert(com.jinye.sms.domain
	 *      .Account)
	 */
	public void insert(Account account)
	{
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * @see com.jinye.sms.persistence.iface.AccountDao#query(java.lang.String)
	 */
	public Account query(String username) throws SQLException
	{

		return (Account) sqlMapClient.queryForObject(username);
	}

	/*
	 * (non-Javadoc)
	 * @see com.jinye.sms.persistence.iface.AccountDao#query()
	 */
	public List<Account> query()
	{
		// TODO Auto-generated method stub
		return null;
	}

	/*
	 * (non-Javadoc)
	 * @see com.jinye.sms.persistence.iface.AccountDao#query(java.util.Map)
	 */
	public List<Account> query(Map<String, Object> map)
	{
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @throws SQLException
	 * @see com.jinye.sms.persistence.iface.AccountDao#query(java.lang.String,
	 *      java.lang.String)
	 */
	@Override
	public Account query(String username, String password) throws SQLException
	{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("username", username);
		map.put("password", password);
		Object result = this.sqlMapClient.queryForObject(
				"queryAccountByNamePassword", map);
		if (null != result)
		{
			return (Account) result;
		}
		return null;
	}

	/*
	 * (non-Javadoc)
	 * @see
	 * com.jinye.sms.persistence.iface.AccountDao#update(com.jinye.sms.domain
	 * .Account)
	 */
	public void update(Account account)
	{
		// TODO Auto-generated method stub

	}

	/**
	 * @param sqlMapClient
	 *            the sqlMapClient to set
	 */
	public void setSqlMapClient(SqlMapClient sqlMapClient)
	{
		this.sqlMapClient = sqlMapClient;
	}

}
